﻿---@diagnostic disable: trailing-space
local extension = Package:new("moepack_moesp3")
extension.extensionName = "moepack"

Fk:loadTranslationTable{
  ["moepack_moesp3"] = "萌包-SP3",
}

local U = require "packages/utility/utility"

local MoeFunc = require "packages/moepack/moepack_function"

local farmer_youmu = General(extension, "moesp__farmer_youmu", "moe", 4, 4, General.Female)

local emo__gongnong = fk.CreateViewAsSkill{
  name = "emo__gongnong",
  pattern = ".|.|.|.|.|basic",
  prompt = "#emo__gongnong",
  frequency = Skill.Compulsory,
  derived_piles = "emo__gongnong_pile",
  interaction = function(self)
    local all_choices = {}
    for _, id in ipairs(Self:getPile("emo__gongnong_pile")) do
      table.insertIfNeed(all_choices, Fk:getCardById(id, true).name)
    end
    local choices = U.getViewAsCardNames(Self, self.name, all_choices)
    if #choices > 0 then
      return U.CardNameBox { choices = choices, all_choices = all_choices }
    end
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local name = self.interaction.data
    if not name then return nil end
    local c = Fk:cloneCard(name)
    c.skillName = self.name
    return c
  end,
  before_use = function(self, player, use)
    local room = player.room
    local cards = table.filter(player:getPile("emo__gongnong_pile"), function (id)
      return Fk:getCardById(id, true).trueName == use.card.trueName
    end)
    if #cards == 0 then return self.name end
    room:recastCard(cards, player, self.name)
  end,
  enabled_at_play = function(self, player)
    return #player:getPile("emo__gongnong_pile") > 0
  end,
  enabled_at_response = function (self, player, response)
    if Fk.currentResponsePattern then
      return table.find(player:getPile("emo__gongnong_pile"), function (id)
        return Exppattern:Parse(Fk.currentResponsePattern):matchExp(Fk:getCardById(id, true).trueName)
      end)
    end
  end,
}

local emo__gongnong_trigger = fk.CreateTriggerSkill{
  name = "#emo__gongnong_trigger",
  main_skill = emo__gongnong,
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished, fk.CardRespondFinished},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(emo__gongnong) and player.phase ~= Player.NotActive and data.card.type == Card.TypeBasic then
      return table.find(Card:getIdList(data.card), function (id)
        return Fk:getCardById(id, true).type == Card.TypeBasic
      end)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = table.filter(Card:getIdList(data.card), function (id)
      return Fk:getCardById(id, true).type == Card.TypeBasic
    end)
    player:addToPile("emo__gongnong_pile", cards, true, "emo__gongnong")
  end,
}
emo__gongnong:addRelatedSkill(emo__gongnong_trigger)

farmer_youmu:addSkill(emo__gongnong)

local emo__daogeng = fk.CreateViewAsSkill{
  name = "emo__daogeng",
  anim_type = "offensive",
  pattern = "savage_assault",
  card_filter = Util.FalseFunc,
  prompt = "#emo__daogeng",
  view_as = function(self, cards)
    local c = Fk:cloneCard("savage_assault")
    c.skillName = self.name
    c:addSubcards(Self:getCardIds("h"))
    return c
  end,
  before_use = function(self, player, use)
    use.extra_data = use.extra_data or {}
    use.extra_data.emo__daogeng_from = player.id
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
  end,
  enabled_at_response = Util.FalseFunc,
  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@emo__daogeng", 0)
  end,
}

local emo__daogeng_trigger = fk.CreateTriggerSkill{
  name = "#emo__daogeng_trigger",
  refresh_events = {fk.Damage, fk.PreCardUse},
  can_refresh = function(self, event, target, player, data)
    if player.dead then return false end
    if event == fk.Damage then
      local useEvent = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if useEvent then
        local use = useEvent.data[1]
        return use.card == data.card and (use.extra_data or {}).emo__daogeng_from == player.id
      end
    else
      return target == player and data.card.trueName == "slash" and player:getMark("@emo__daogeng") > 0
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damage then
      room:addPlayerMark(player, "@emo__daogeng")
    else
      room:removePlayerMark(player, "@emo__daogeng")
      data.extraUse = true
    end
  end,
}
emo__daogeng:addRelatedSkill(emo__daogeng_trigger)

local emo__daogeng_targetmod = fk.CreateTargetModSkill{
  name = "#emo__daogeng_targetmod",
  bypass_times = function(self, player, skill, scope, card)
    return card and card.trueName == "slash" and player:getMark("@emo__daogeng") > 0
  end,
}
emo__daogeng:addRelatedSkill(emo__daogeng_targetmod)

farmer_youmu:addSkill(emo__daogeng)

Fk:loadTranslationTable{
  ["moesp__farmer_youmu"] = "农妖梦",
  ["#moesp__farmer_youmu"] = "苍天的农师",
  ["designer:moesp__farmer_youmu"] = "妖梦厨",
  ["illustrator:moesp__farmer_youmu"] = "AI",

  ["emo__gongnong"] = "躬农",
  [":emo__gongnong"] = "锁定技，你的回合内有基本牌结算后，你将此牌置于武将牌上；你可以重铸武将牌上的所有同名牌，视为使用或打出之。",
  ["emo__gongnong_pile"] = "农",
  ["#emo__gongnong_trigger"] = "躬农",
  ["#emo__gongnong"] = "躬农：选择你要视为使用打出的牌，重铸所有“躬农”牌视为使用打出之",

  ["emo__daogeng"] = "刀耕",
  [":emo__daogeng"] = "出牌阶段限一次，你可以将所有手牌当【南蛮入侵】使用；此牌造成伤害后，令你下一张【杀】便无次数限制。",
  ["#emo__daogeng"] = "刀耕：将所有手牌当【南蛮入侵】使用",
  ["@emo__daogeng"] = "刀耕",
}
















--[[

local moesp__xxxx = General(extension, "moesp__xxxx", "moe", 4, 4, General.Female)

Fk:loadTranslationTable{
  ["moesp__xxxx"] = "",
  ["designer:moesp__xxxx"] = "",
  
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",

  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
}

--]]











return extension

